<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
     append-to-body
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <!-- <el-col :span="12">
            <el-form-item label="楼盘名称" prop="buildingsName"
                :rules="[
                  {required: true, message:'楼盘ID不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.buildingsId" placeholder="请填写楼盘ID"     ></el-input>
           </el-form-item>
        </el-col> -->
        <el-col :span="12">
            <el-form-item label="预售证号" prop="presaleNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.presaleNo" placeholder="请填写预售证号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="绑定楼栋" prop="boundBuilding"
                :rules="[
                 ]">
              <el-input v-model="inputForm.boundBuilding" placeholder="请填写绑定楼栋"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="发证时间" prop="IssuingTime"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.IssuingTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
            <el-form-item label="审核状态" prop="auditStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.auditStatus" placeholder="请选择"  style="width: 100%;">
                  <el-option label="待审核" value="0">待审核</el-option>
                  <el-option label="已审核" value="1">已审核</el-option> 
                  <el-option label="已拒绝" value="2">已拒绝</el-option> 
                </el-select>
           </el-form-item>
        </el-col> -->
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button v-if="inputForm.auditStatus == 0" @click="audit(inputForm.id,1)">通过</el-button>
          <el-button v-if="inputForm.auditStatus == 0" @click="jj(inputForm.id,2)">拒绝</el-button>
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          buildingsId: '',
          presaleNo: '',
          boundBuilding: '',
          IssuingTime: '',
          auditStatus: '0',
          remarks: ''
        }
      }
    },
    components: {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.buildingsId = ''
        if (method === 'add') {
          this.inputForm.buildingsId = id
          this.title = `新建预售许可信息列表`
        } else if (method === 'edit') {
           this.inputForm.id = id
          this.title = '修改预售许可信息列表'
        } else if (method === 'view') {
           this.inputForm.id = id
          this.title = '查看预售许可信息列表'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/tsellinglicense/tSellingLicense/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.tSellingLicense)
              this.loading = false
            })
          }
        })
      },
      audit(id,status) { 
        this.$confirm(`确定当前操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.$http({
            url: '/tsellinglicense/tSellingLicense/audit',
            method: 'post',
            params: {'id': id,"auditStatus":status}
          }).then(({data}) => {
            if (data && data.success) {
               this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
            }
            this.visible = false
            
            
          })
        })
      },
      jj(id,status){
        this.$confirm(`确定当前操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.$http({
            url: '/tsellinglicense/tSellingLicense/audit',
            method: 'post',
            params: {'id': id,"auditStatus":status}
          }).then(({data}) => {
            if (data && data.success) {
               this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
            }
            this.visible = false
            
           
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          });       
        });
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/tsellinglicense/tSellingLicense/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>